<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="../../../res/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../res/css/common/font-awesome.min.css" media="all">
		<link rel="stylesheet" href="../../../res/layui-config/css/app.css" media="all">
		<title>财务审核</title>
	</head>
	<body>
		<div class="kit-table">
		    <form class="layui-form" lay-filter="kit-search-form">
				<!-- 左上角的两个按钮 -->
		        <div class="kit-table-header">
		            <div style="left:30px;" class="kit-search-inputs">
		                <div class="kit-search-keyword">
		                    <input type="text" class="layui-input" id="serach-one" placeholder="药品.." onKeyUp="lockInput(this,'serach-two')"/>
		                    <button style="left:170px;" lay-submit lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
		                </div>
		                <div style="left:230px;" class="kit-search-more" id="kit-search-more">更多筛选<i class="layui-icon">&#xe61a;</i></div>
		            </div>
		        </div>
				<!-- 搜索扩展工具条 -->
		        <div class="kit-search-mored layui-anim layui-anim-upbit">
		            <div class="kit-search-body">
		                <div class="layui-form-item">
		                    <label class="layui-form-label">药品名称</label>
		                    <div class="layui-input-block">
		                        <input type="text" name="drugName" id="serach-two" placeholder="搜索关键字.." autocomplete="off" class="layui-input" onKeyUp="lockInput(this,'serach-one')">
		                    </div>
		                </div>
		                <div class="layui-form-item">
			                <label class="layui-form-label">类型</label>
			                <div class="layui-input-block">
			                    <select name="dtId" id="drug-type">
			                      <option value=""></option>
			                    </select>
			                </div>
		                </div>
		                <div class="layui-form-item">
		                    <div class="layui-inline">
		                        <label class="layui-form-label">范围</label>
		                        <div class="layui-input-block">
			                        <div class="layui-input-inline" style="width: 100px;">
			                            <input type="text" name="priceMin" placeholder="￥" autocomplete="off" class="layui-input" maxlength="6" onKeyUp="amount(this)">
			                        </div>
			                        <div class="layui-form-mid">-</div>
			                        <div class="layui-input-inline" style="width: 100px;">
			                            <input type="text" name="priceMax" placeholder="￥" autocomplete="off" class="layui-input" maxlength="6" onKeyUp="amount(this)">
			                        </div>
		                        </div>
		                    </div>
		                </div>
		            </div>
		            <div class="kit-search-footer">
		                <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary kit-btn reset-btn">重置</button>
		                <button lay-submit lay-filter="search" class="layui-btn layui-btn-sm kit-btn">确定</button>
		            </div>
		        </div>
		    </form>
			<!-- 操作按钮 -->
		    <div class="kit-table-body">
		        <table id="demo" lay-filter="demo"></table>
		         
				<script type="text/html" id="switchTpl">
  					<!-- 这里的 checked 的状态只是演示 -->
  					<input type="checkbox" disabled name="audState" value="{{d.audState}}"  lay-skin="switch" lay-text="通过|未过" lay-filter="sexDemo">
				</script>
		        <script type="text/html" id="barDemo">
		            <a class="layui-btn layui-btn-xs" lay-event="detail">查看订单</a>
					<button class="layui-btn layui-btn-xs" lay-event="shenhe">审核</button>
		        </script>
		    </div>
		</div>
		
		<!-- 修改页面 -->
		<script type="text/html" id="edit-tpl">
		    <div style="margin:10px">
		        <form class="layui-form" action="" lay-filter="form-edit">
 				<input type="hidden" name="audId" value="{{d.rowdata.audId}}" />
		            <div class="layui-form-item">
		                <label class="layui-form-label">审核部门</label>
		                <div class="layui-input-block">
		                    <input class="layui-input layui-disabled" required lay-verify="required" value="财务审核"  autocomplete="off" class="layui-input">
		                </div>
		            </div>
					<div class="layui-form-item">
		                <label class="layui-form-label">订单名称</label>
		                <div class="layui-input-block">
		                    <input class="layui-input layui-disabled" name="matAmount" required lay-verify="required" value="批发财务审核"  autocomplete="off" class="layui-input">
		                </div>
		            </div>
					
					<div class="layui-form-item">
		                <label class="layui-form-label">是否通过</label>
		                <div class="layui-input-block">
		                    {{# var woman = d.rowdata.audState === 28?'checked':'';}} {{# var man = d.rowdata.audState === 29?'checked':'';}}
		                    <input type="radio" name="audState" value="29" title="是" {{man}} />
		                    <input type="radio" name="audState" value="28" title="否" {{woman}} />
		                </div>
		            </div>

					<div class="layui-form-item">
		                <label class="layui-form-label">审核意见</label>
		                <div class="layui-input-block">
		                    <input type="text" name="audIdea" required lay-verify="required" value="{{d.rowdata.audIdea}}" autocomplete="off" class="layui-input">
		                </div>
		            </div>
		            
		            <div class="layui-form-item" style="display:none;">
		                <div class="layui-input-block">
		                    <button class="layui-btn" lay-submit lay-filter="formEdit">立即提交</button>
		                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		                </div>
		            </div>
		        </form>
		    </div>
		</script>
		
		
		<script src="../../../res/js/common/jquery-1.11.2.min.js"></script>
		<script>
			//文本框只能输入金额
		    function amount(th){
		        var regStrs = [
		            ['^0(\\d+)$', '$1'], //禁止录入整数部分两位以上，但首位为0
		            ['[^\\d\\.]+$', ''], //禁止录入任何非数字和点
		            ['\\.(\\d?)\\.+', '.$1'], //禁止录入两个以上的点
		            ['^(\\d+\\.\\d{2}).+', '$1'] //禁止录入小数点后两位以上
		        ];
		        for(i=0; i<regStrs.length; i++){
		            var reg = new RegExp(regStrs[i][0]);
		            th.value = th.value.replace(reg, regStrs[i][1]);
		        }
		    }
			//搜索框同步输入
			function lockInput(obj,id){
				$("#"+id).val($(obj).val());
			}
		</script>
		<script src="../../../res/layui/layui.all.js"></script>
		<script>
			//显示表格数据
			 var tableElem="";
		    layui.use(['table','upload'], function() {
		        var table = layui.table,
		            $ = layui.jquery,
		            layer = layui.layer,
		            form = layui.form,
		            laytpl = layui.laytpl;
		        var tableIns = table.render({
		            elem: '#demo',
		            height: '475px', //容器高度
		            url: '../../../audit/wholeceo.action',
		            page: true,
		            id: 'demo',
		            cols: [
		                [{type: 'checkbox',fixed: true},
		                {field: 'audFkId',title: '业务编号',width: 225},
		                {field: 'audTimes',title: '审核时间',width: 160},
		                {field: 'audState',title: '审核状态',width: 140,templet: '#switchTpl', unresize: true},
		                {field: 'wholAmount',title: '总数量',width: 150},
		                {field: 'wholPrice',title: '总价格',width: 150},
		                {fixed: 'right',title: '操作',width: 180,align: 'center',toolbar: '#barDemo'}]
		            ],
		            done: function(res, curr, count) {
		            	tableElem=this.elem.next('.layui-table-view');
		            	$("[data-field = 'audState']").children().not(":first").each(function(indexs){
		            		$.each($(this).find('input'),function(index,item){
		            			if($(this).val() == '29'){
		            				$(this).prop("checked",true);
		            				tableElem.find('tr[data-index="' + indexs + '"]').find('button[lay-event=shenhe]').addClass('layui-btn-disabled').attr('disabled',true);
							    }
		            		});
		            		renderForm();
		            	});
		            },
		            loading: true
		        });
		        //监听性别操作
		        form.on('switch(sexDemo)', function(obj){
		          layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
		        });
		        
		        //监听搜索表单提交
		        form.on('submit(search)', function(data) {
		            //带条件查询
		            tableIns.reload({
		                where: data.field,
		                page: { curr: 1 }
		            });
		            $('.kit-search-mored').hide();
		            return false;
		        });
		      //渲染 修改和增加弹出层
			    function showlayer(d){
			    	laytpl($('#edit-tpl').html()).render(d,function(html) {
	                    layer.open({
	                        type: 1,
	                        title: '审核',
	                        content: html,
	                        area: ['800px', '430px'],
	                        btn: ['提交', '重置', '取消'],
	                        yes: function(index, layero) {
	                            editIndex = index;
	                            $('form[lay-filter="form-edit"]').find('button[lay-submit]').click();
	                        },
	                        btn2: function(index, layero) {
	                            $('form[lay-filter="form-edit"]').find('button[type="reset"]').click();
	                            return false;
	                        },
	                        success: function() {
	                            form.render(null, 'form-edit');
	                        }
	                    });
	                    
	                });
			    }
		        
		        
		        //监听工具条按钮点击
		        table.on('tool(demo)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
		            var data = obj.data; //获得当前行数据
		            var layEvent = obj.event; //获得 lay-event 对应的值
		            var tr = obj.tr; //获得当前行 tr 的DOM对象
		            if (layEvent === 'detail') { //审核
		            	layer.open({
                            type: 2,
                            title: '增加批发订单',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['900px', '450px'],
                            content: '../../wholesale/detailwhol.html?whoid='+data.audFkId+''
                        });
		            } else if (layEvent === 'shenhe') {
		            	var d = {
			                	rowdata: {audId: data.audId,audIdea:'',audState:29}
			                };
		            	showlayer(d);
		            }else if (layEvent === 'details') {
		            	layer.open({
                            type: 2,
                            title: '增加批发订单',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['900px', '450px'],
                        });
		            }
		        });
		        
		      //审核提交
		        form.on('submit(formEdit)', function(data) {
		        	update("../../../audit/examine.action",data.field);
		        	editIndex && layer.close(editIndex); //关闭弹出层
                	return false;
		        });
		        
		        
		        //表单渲染
		        form.render(null, 'kit-search-form');
		        //更多筛选点击事件
		        $('#kit-search-more').on('click', function() {
		            $('.kit-search-mored').toggle();
		        });
		    });
		  	//重新渲染表 单
		  	function renderForm(){ 
	  			layui.use('form', function(){ 
		  			var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加() 
		  			form.render(); 
	  			}); 
	  		}
		  	
		    //ajax加载动画
		    $(function () {
	            $.ajaxSetup({
	                layerIndex:-1,
	                beforeSend: function () {
	                    this.layerIndex = layer.load(1, { shade: [0.8, '#ffffff'] });
	                },
	                complete: function () {
	                    layer.close(this.layerIndex);
	                },
	                error: function () {
	                    layer.alert('部分数据加载失败，可能会导致页面显示异常，请刷新后重试', {
	                        skin: 'layui-layer-molv'
	                       , closeBtn: 0
	                       , shift: 4 //动画类型
	                    });
	                }
	            });
	        });
		    
		    
		    
		  //增加、修改、删除、批量删除 都是用的这一个方法
		    function update(url,data){
		    	$.ajax({
		    		url: url,
                    type:'post',//method请求方式，get或者post
                    cache: false,//同步
                    dataType:'json',//预期服务器返回的数据类型
                    data: JSON.stringify(data),//表格数据序列化
                    contentType: "application/json; charset=utf-8",
                    success:function(mes){//res为相应体,function为回调函数
                    	$(".layui-laypage-btn")[0].click();//当前表格刷新
                        if(mes.status==1){ 
                        	var close = true;//有弹出层时是关闭弹出层 false不关闭
	                        $("#res").click();//调用重置按钮将表单数据清空
                        }
                        layer.msg(mes.msg);
                    },
                   	error:function(){layer.alert('数据异常，请稍后重试！！！',{icon:5});}
                 });
		    }
		</script>
	</body>